//
//  RightTableViewCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/8/3.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

protocol RightTableViewCellDeleage : NSObjectProtocol {
    
    func rightTableViewCellBtnDidTap(model: OneItemModel)
    
}

class RightTableViewCell: BaseTableViewCell {
    
    weak var delegate : RightTableViewCellDeleage?
    
    @IBOutlet weak var imageView1: UIImageView!
    
    @IBOutlet weak var imageView2: UIImageView!
    
    @IBOutlet weak var imageView3: UIImageView!
    
    @IBOutlet weak var label1: UILabel!
    
    @IBOutlet weak var label3: UILabel!

    @IBOutlet weak var label2: UILabel!
    
    @IBOutlet weak var indicatorView1: UIActivityIndicatorView!
    
    @IBOutlet weak var indicatorView2: UIActivityIndicatorView!
    
    @IBOutlet weak var indicatorView3: UIActivityIndicatorView!
    
    
    @IBOutlet weak var btn1: UIButton!
    
    @IBOutlet weak var btn2: UIButton!
    
    @IBOutlet weak var btn3: UIButton!
    
    var models : [OneItemModel]?{
    
        didSet{
            
            if models == nil {
                
                btn1.backgroundColor = UIColor.white
                btn1.isUserInteractionEnabled = false
                
                btn2.backgroundColor = UIColor.white
                btn2.isUserInteractionEnabled = false
                
                btn3.backgroundColor = UIColor.white
                btn3.isUserInteractionEnabled = false
                
                return
            }
        
            switch models!.count {
                 case 1:
                    let model1 = models![0]
                    
                    indicatorView1.startAnimating()
                    imageView1.sd_setImage(with: URL(string: model1.gc_image), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                        self.indicatorView1.stopAnimating()
                        
                }
                

                    label1.text = model1.gc_name
                
                    btn1.backgroundColor = UIColor.clear
                    btn1.isUserInteractionEnabled = true
                    
                    btn2.backgroundColor = UIColor.white
                    btn2.isUserInteractionEnabled = false
                    
                    btn3.backgroundColor = UIColor.white
                    btn3.isUserInteractionEnabled = false
                
                 case 2:
                    let model1 = models![0]
                    let model2 = models![1]

                    indicatorView1.startAnimating()
                    imageView1.sd_setImage(with: URL(string: model1.gc_image), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                        self.indicatorView1.stopAnimating()
                        
                }
                
                    indicatorView2.startAnimating()
                    imageView2.sd_setImage(with: URL(string: model2.gc_image), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                        self.indicatorView2.stopAnimating()
                        
                }

                    label1.text = model1.gc_name
                    label2.text = model2.gc_name
                
                
                    btn1.backgroundColor = UIColor.clear
                    btn1.isUserInteractionEnabled = true
                    
                    btn2.backgroundColor = UIColor.clear
                    btn2.isUserInteractionEnabled = true
                    
                    btn3.backgroundColor = UIColor.white
                    btn3.isUserInteractionEnabled = false

                
                 case 3:
                    let model1 = models![0]
                    let model2 = models![1]
                    let model3 = models![2]
                    
                    indicatorView1.startAnimating()
                    imageView1.sd_setImage(with: URL(string: model1.gc_image), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                        self.indicatorView1.stopAnimating()
                        
                }

                    indicatorView2.startAnimating()
                    imageView2.sd_setImage(with: URL(string: model2.gc_image), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                        self.indicatorView2.stopAnimating()
                        
                }

                
                    indicatorView3.startAnimating()
                    imageView3.sd_setImage(with: URL(string: model3.gc_image), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                        self.indicatorView3.stopAnimating()
                        
                }
                
                
                    label1.text = model1.gc_name
                    label2.text = model2.gc_name
                    label3.text = model3.gc_name

                
                    btn1.backgroundColor = UIColor.clear
                    btn1.isUserInteractionEnabled = true
                    
                    btn2.backgroundColor = UIColor.clear
                    btn2.isUserInteractionEnabled = true
                    
                    btn3.backgroundColor = UIColor.clear
                    btn3.isUserInteractionEnabled = true

            default:

                QL1("默认")

            }
        
        
        }
    
    
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        label1.textColor = UIColor.dakGray()
        label2.textColor = UIColor.dakGray()
        label3.textColor = UIColor.dakGray()
        
        

        // Initialization code
    }
    
    
    
    @IBAction func btn1DidTap(_ sender: UIButton) {
        delegate?.rightTableViewCellBtnDidTap(model: models![0])
    }
    
    
    @IBAction func btn2DidTap(_ sender: UIButton) {
        delegate?.rightTableViewCellBtnDidTap(model: models![1])

        
    }
    
    
    
    @IBAction func btn3DidTap(_ sender: UIButton) {
        
        delegate?.rightTableViewCellBtnDidTap(model: models![2])

    }
    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
